<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目任务管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="项目任务管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'projectName',width:80,align:'center'">项目</th>
				<th data-options="field:'projectTaskTypeName',width:80,align:'center'">任务类型</th>
				<th data-options="field:'taskDescription',width:200,align:'center'">任务描述</th>
				<th data-options="field:'planFinishDate',width:100,align:'center'">计划完成日期</th>
				<th data-options="field:'status',width:60,align:'center'">状态</th>
				<th data-options="field:'id',width:80,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem')">新增</a>
		</div>
		<div>
			项目名称:
			<select data-options="editable: false" id = "project" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projects }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			创建人:
			<select data-options="editable: false" id = "people" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${peoples }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			任务类型:
			<select data-options="editable: false" id = "projectTaskType" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectTaskTypes }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			发布时间: <input class="easyui-datebox" type="text" id="taskPublishTimeBegin" style="width:100px;height:25px;">
			~ <input class="easyui-datebox" type="text" id="taskPublishTimeEnd" style="width:100px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="项目任务详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:820px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td width="250px;" align="right">项目名称：</td>
						<td>
							<select id="lookProjectId" class="easyui-combobox" data-options="required:true" disabled="disabled">
								<c:forEach var="item" items="${projects }" >
									<option value = "${item.id }">${item.name }</option>
								</c:forEach>
							</select>
						</td>
						<td width="170px;" align="right">创建人：</td>
						<td>
							<select id="lookTaskCreatorId" class="easyui-combobox" data-options="required:true" disabled="disabled">
								<c:forEach var="item" items="${peoples }" >
									<option value = "${item.id }">${item.name }</option>
								</c:forEach>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">任务类型：</td>
						<td>
							<select id="lookProjectTaskTypeId" class="easyui-combobox" data-options="required:true" disabled="disabled">
								<c:forEach var="item" items="${projectTaskTypes }" >
									<option value = "${item.id }">${item.name }</option>
								</c:forEach>
							</select>
						</td>
						<td align="right">状态：</td>
						<td>
							<input class="easyui-textbox" id="lookStatus" data-options="required:true" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">创建日期：</td>
						<td>
							<input class="easyui-datebox" id="lookTaskCreateTime" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">发布日期：</td>
						<td>
							<input class="easyui-datebox" id="lookTaskPublishTime" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">任务描述：</td>
						<td colspan="3">
							<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 570px; height: 80px;" id="lookTaskDescription" readonly="readonly">
						</td>
					</tr>
					<tr>
						<td align="right">计划开始日期：</td>
						<td>
							<input class="easyui-datebox" id="lookTaskBeginDate" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">初次计划完成日期：</td>
						<td>
							<input class="easyui-datebox" id="lookFirstPlanFinishDate" data-options="required:true" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">计划完成日期：</td>
						<td>
							<input class="easyui-datebox" id="lookPlanFinishDate" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">任务领取日期：</td>
						<td>
							<input class="easyui-datebox" id="lookTaskAcceptTime" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">计划工时数：</td>
						<td>
							<input class="easyui-textbox" id="lookPlanWorktime" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">实际工时数：</td>
						<td>
							<input class="easyui-textbox" id="lookActualWorktime" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">计划完成日期变更次数：</td>
						<td >
							<input class="easyui-textbox" id="lookPlanFinishDateChangeCount" readonly="readonly" />
						</td>
					</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增项目任务" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:770px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editProjectTask" style = "width:100%; height: 100%">
					<input type="hidden" name="planFinishDateChangeCount" value="0" />
					<table width="100%" height="100%">
						<tr>
							<td width="170px;" align="right">项目名称：</td>
							<td>
								<select name = "project.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projects }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="170px;" align="right">创建人：</td>
							<td>
								<select name = "taskCreator.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${peoples }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">任务类型：</td>
							<td>
								<select name = "projectTaskType.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTaskTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">状态：</td>
							<td>
								<input class="easyui-textbox" name="status" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">创建日期：</td>
							<td>
								<input class="easyui-datebox" name="taskCreateTime" data-options="required:true" />
							</td>
							<td align="right">发布日期：</td>
							<td>
								<input class="easyui-datebox" name="taskPublishTime" />
							</td>
						</tr>
						<tr>
							<td align="right">任务描述：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 570px; height: 80px;" name="taskDescription">
							</td>
						</tr>
						<tr>
							<td align="right">计划开始日期：</td>
							<td>
								<input class="easyui-datebox" name="taskBeginDate" data-options="required:true" />
							</td>
							<td align="right">初次计划完成日期：</td>
							<td>
								<input class="easyui-datebox" name="firstPlanFinishDate" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">计划完成日期：</td>
							<td>
								<input class="easyui-datebox" name="planFinishDate" data-options="required:true" />
							</td>
							<td align="right">任务领取日期：</td>
							<td>
								<input class="easyui-datebox" name="taskAcceptTime" />
							</td>
						</tr>
						<tr>
							<td align="right">计划工时数：</td>
							<td>
								<input class="easyui-textbox" name="planWorktime" data-options="required:true" />
							</td>
							<td align="right">实际工时数：</td>
							<td>
								<input class="easyui-textbox" name="actualWorktime" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑项目任务" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:770px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editProjectTask" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<input type="hidden" id="editPlanFinishDateChangeCount" name="planFinishDateChangeCount" />
					<table width="100%" height="100%">
						<tr>
							<td width="170px;" align="right">项目名称：</td>
							<td>
								<select name = "project.id" id="editProjectId" class="easyui-combobox" data-options="required:true">
									<c:forEach var="item" items="${projects }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="170px;" align="right">创建人：</td>
							<td>
								<select name = "taskCreator.id" id="editTaskCreatorId" class="easyui-combobox" data-options="required:true">
									<c:forEach var="item" items="${peoples }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">任务类型：</td>
							<td>
								<select name = "projectTaskType.id" id="editProjectTaskTypeId" class="easyui-combobox" data-options="required:true">
									<c:forEach var="item" items="${projectTaskTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">状态：</td>
							<td>
								<input class="easyui-textbox" name="status" id="editStatus" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">创建日期：</td>
							<td>
								<input class="easyui-datebox" name="taskCreateTime" id="editTaskCreateTime" data-options="required:true" />
							</td>
							<td align="right">发布日期：</td>
							<td>
								<input class="easyui-datebox" name="taskPublishTime" id="editTaskPublishTime" />
							</td>
						</tr>
						<tr>
							<td align="right">任务描述：</td>
							<td colspan="3">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 410px; height: 80px;" name="taskDescription" id="editTaskDescription">
							</td>
						</tr>
						<tr>
							<td align="right">计划开始日期：</td>
							<td>
								<input class="easyui-datebox" name="taskBeginDate" id="editTaskBeginDate" data-options="required:true" />
							</td>
							<td align="right">初次计划完成日期：</td>
							<td>
								<input class="easyui-datebox" name="firstPlanFinishDate" id="editFirstPlanFinishDate" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">计划完成日期：</td>
							<td>
								<input class="easyui-datebox" name="planFinishDate" id="editPlanFinishDate" data-options="required:true" />
							</td>
							<td align="right">任务领取日期：</td>
							<td>
								<input class="easyui-datebox" name="taskAcceptTime" id="editTaskAcceptTime" />
							</td>
						</tr>
						<tr>
							<td align="right">计划工时数：</td>
							<td>
								<input class="easyui-textbox" name="planWorktime" id="editPlanWorktime" data-options="required:true" />
							</td>
							<td align="right">实际工时数：</td>
							<td>
								<input class="easyui-textbox" name="actualWorktime" id="editActualWorktime" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + val + ')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var project = $("#project").combobox("getValue");
			var people = $("#people").combobox("getValue");
			var projectTaskType = $("#projectTaskType").combobox("getValue");
			var taskPublishTimeBegin = $("#taskPublishTimeBegin").textbox("getValue").trim();
			var taskPublishTimeEnd = $("#taskPublishTimeEnd").textbox("getValue").trim();
			var url = "queryProjectTask?projectId=" + project + "&taskCreatorId=" + people + "&projectTaskTypeId=" + projectTaskType + "&taskPublishTimeBegin=" + taskPublishTimeBegin + "&taskPublishTimeEnd=" + taskPublishTimeEnd;
			dg.datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProjectTask",
			  	data: params,
			  	success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#lookPlanFinishDateChangeCount").textbox("setValue", item.planFinishDateChangeCount + "");
						$("#lookProjectId").combobox("setValue", item.projectId);
						$("#lookTaskCreatorId").combobox("setValue", item.taskCreatorId);
						$("#lookProjectTaskTypeId").combobox("setValue", item.projectTaskTypeId);
						$("#lookTaskCreateTime").textbox("setValue", item.taskCreateTime);
						$("#lookTaskPublishTime").textbox("setValue", item.taskPublishTime);
						$("#lookTaskBeginDate").textbox("setValue", item.taskBeginDate);
						$("#lookFirstPlanFinishDate").textbox("setValue", item.firstPlanFinishDate);
						$("#lookPlanFinishDate").textbox("setValue", item.planFinishDate);
						$("#lookTaskAcceptTime").textbox("setValue", item.taskAcceptTime);
						$("#lookTaskDescription").textbox("setValue", item.taskDescription);
						$("#lookPlanWorktime").textbox("setValue", item.planWorktime);
						$("#lookActualWorktime").textbox("setValue", item.actualWorktime);
						$("#lookStatus").textbox("setValue", item.status);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function editItem(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProjectTask",
			  	data: params,
			  	success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#editId").val(id);
						$("#editPlanFinishDateChangeCount").val(item.planFinishDateChangeCount);
						$("#editProjectId").combobox("setValue", item.projectId);
						$("#editTaskCreatorId").combobox("setValue", item.taskCreatorId);
						$("#editProjectTaskTypeId").combobox("setValue", item.projectTaskTypeId);
						$("#editTaskCreateTime").textbox("setValue", item.taskCreateTime);
						$("#editTaskPublishTime").textbox("setValue", item.taskPublishTime);
						$("#editTaskBeginDate").textbox("setValue", item.taskBeginDate);
						$("#editFirstPlanFinishDate").textbox("setValue", item.firstPlanFinishDate);
						$("#editPlanFinishDate").textbox("setValue", item.planFinishDate);
						$("#editTaskAcceptTime").textbox("setValue", item.taskAcceptTime);
						$("#editTaskDescription").textbox("setValue", item.taskDescription);
						$("#editPlanWorktime").textbox("setValue", item.planWorktime);
						$("#editActualWorktime").textbox("setValue", item.actualWorktime);
						$("#editStatus").textbox("setValue", item.status);

						$('#editItem').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的项目任务吗？", function(r){
				if(r){
					var params = "id=" + id;
					$.ajax({
					  	type: "GET",
					  	url: "delProjectTask",
					  	data: params,
					  	success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '删除成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  	}
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '添加成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '修改成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			//validateMenu
			search();//页面装载完成后加载数据
		});
	</script>
</body>
</html>